package com.xiaohe.gulimall.seckill.vo;

import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;


public class Cart {
    private List<CartItem> cartItems;

    private Integer countNum;

    private Integer countType;//类型

    private BigDecimal totalAmount;

    private BigDecimal reduce = new BigDecimal("0.00");//减免价格

    public List<CartItem> getCartItems() {
        return cartItems;
    }

    public void setCartItems(List<CartItem> cartItems) {
        this.cartItems = cartItems;
    }

    public Integer getCountNum() {
        int count = 0;
        if(cartItems!=null&&cartItems.size()>0){
            for (CartItem cartItem : cartItems) {
                count+= cartItem.getCount();
            }
        }
        return count;
    }

    public Integer getCountType() {
        int count = 0;
        if(cartItems!=null&&cartItems.size()>0){
            for (CartItem cartItem : cartItems) {
                count+= 1;
            }
        }
        return count;
    }

    //总价
    public BigDecimal getTotalAmount() {
        BigDecimal amount = new BigDecimal("0");
        // 计算购物项总价
        if (!CollectionUtils.isEmpty(cartItems)) {
            for (CartItem cartItem : cartItems) {
                if (cartItem.getCheck()) {
                    amount = amount.add(cartItem.getTotalPrice());
                }
            }
        }
        // 计算优惠后的价格
        return amount.subtract(getReduce());
    }

    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
